import * as echarts from "echarts";
const font_size = 16

// 仿真数据格式用于使用者确认格式用的
export const _ec_data_format = {
	series: {
		bar: [
			{
				name: "一级",
				value: 10,
				color: "255, 0, 0",
			},
			{
				name: "一级",
				value: 10,
				color: "255, 0, 0",
			},
			{
				name: "一级",
				value: 10,
				color: "255, 0, 0",
			},
			{
				name: "一级",
				value: 10,
				color: "255, 0, 0",
			},
		
		
		],
		line: [3, 7, 2, 2, 3, 1, 1, 4, 1, 3, 5, 6, 3, 1, 1, 3, 2],
	}
};

/**
 * @description: 生成ec图表配置信息
 * @author: 王琛
 * @Date: 2022-11-25 15:29:43
 * @param {*}
 * @return {*}
 */
export function getOptions({series = [], color = '43, 91, 243'} = {}) {
	let bar_series = [];
	let line_series = [];
	if (!series.length) {
		bar_series = _ec_data_format["series"]["bar"];
		line_series = _ec_data_format["series"]["line"];
	}
	// y轴分类种类
	let xaxisData_bar = [];
	// x轴的数据
	let yaxisData_bar = [];
	
	for (let i = 0, len = bar_series.length; i < len; i++) {
		const bar_series_item = bar_series[i];
		yaxisData_bar.push(bar_series_item.name)
		xaxisData_bar.push(bar_series_item.value)
	}
	
	// 柱形图的宽度
	let item_bar_w = 10;
	// 主配置文件
	let options = {
		tooltip: {},
		grid: {
			left: "0%",
			right: 0,
			top: 10,
			bottom: "0%",
			containLabel: true,
		},
		xAxis: [
			{
				type: "category",
				axisLabel: {
					interval: 0,
					color: "#fff",
					fontSize: font_size,
				},
				axisLine: {
					lineStyle: {
						//y轴网格线设置
						color: "rgba(0, 168, 255, 0.4)",
						width: 1,
					},
				},
				
				splitLine: {
					show: false,
				},
				axisTick: {
					show: false,
				},
				data: yaxisData_bar
			},
		],
		yAxis: [
			{
				type: "value",
				name: "",
				nameTextStyle: {
					color: "#fff",
					fontWeight: 400,
					fontSize: font_size,
				},
				axisTick: {
					show: false,
				},
				axisLine: {
					show: false,
				},
				splitLine: {
					lineStyle: {
						type: "solid",
						opacity: 0.4
					}
				},
				axisLabel: {
					show: true,
					fontSize: font_size,
					color: "#fff",
				},
			},
			{
				type: "value",
				name: "",
				position: "right",
				nameTextStyle: {
					color: "#fff",
					fontWeight: 400,
					fontSize: font_size,
				},
				axisTick: {
					show: false,
				},
				axisLine: {
					show: false,
				},
				splitLine: {
					show: false,
					lineStyle: {
						type: "solid",
						opacity: 0.4
					}
				},
				axisLabel: {
					show: true,
					fontSize: font_size,
					color: "#fff",
				},
			},
		],
		series: [
			{
				type: "bar",
				barWidth: item_bar_w,
				label: {
					show: false,
				},
				itemStyle: {
					borderRadius: [item_bar_w / 3, item_bar_w / 3, item_bar_w / 3, item_bar_w / 3],
					color: (parameter) => {
						return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
							{
								offset: 0,
								color: `rgba(${color}, 1)`,
							},
							{
								offset: 0.5,
								color: `rgba(${color}, 1)`,
							},
							{
								offset: 1,
								color: `rgba(${color}, 0)`,
							},
						])
					}
				},
				data: xaxisData_bar,
			},
			{
				name: '',
				type: 'line',
				showAllSymbol: true,
				symbol: 'circle',
				yAxisIndex: 1,
				symbolSize: 8,
				lineStyle: {
					normal: {
						color: `rgba(${color},1)`,
					},
				},
				label: {
					show: false,
				},
				
				itemStyle: {
					color: "#fff",
					borderColor: `rgba(${color},1)`,
					borderWidth: 3,
				},
				data: line_series
			}
		],
	};
	return options;
}

/**
 * @description: 有些表图数据需要通过js处理得到,结合实际业务来确定师傅哦哦使用次函数,如不适用可以删除掉
 * @author: 王琛
 * @Date: 2023-03-09 14:53:48
 * @param {*}
 * @return {*}
 */
export function getSeries({} = {}) {
	let _series = {};
	return _series;
}





